<script language='JavaScript1.2'>
	function updateRequestStatus(selectElement, requestId, noticeTarget)
	{
		var path = './json/request/status/' + requestId;
		var successHtml = '<img style="vertical-align:middle;" src="public/images/icons/check.png" alt="status update succeeded">';
		var failHtml = '<img style="vertical-align:middle;" src="public/images/icons/cross.png" alt="status update failed">';
		var waitHtml = '<img style="vertical-align:middle;" src="public/images/icons/ajax-loader.gif" alt="status update pending">';
		$(noticeTarget).html(waitHtml);
		$.ajax({
			url: path,
			type: 'POST',
			data: {'status' : selectElement.value},
			dataType: 'json',
			success: function(data){ 
				if (data && data.success ) {
					if ( 
						data.request 
						&& data.request[0]
						&& data.request[0].status == selectElement.value
					) {
						$(noticeTarget).html(successHtml);
					} else {
						alert('Unexpectd error, status not set correctly.');
						$(noticeTarget).html(failHtml);
					}
				} else {
					if (data && data.message) {
						alert(data.message);
					} else {
						alert('failed to update this request\'s status.');
					}
					$(noticeTarget).html(failHtml);
				}				
			},
			error : function(junk, junk2, junk3){
				$(noticeTarget).html(failHtml);
				alert('failed to update this request\'s status.');
			}
		});	
		return false;
	}
</script>
<div class="preloadIcons">
	<img style="vertical-align:middle;" src="public/images/icons/check.png" alt="">
	<img style="vertical-align:middle;" src="public/images/icons/cross.png" alt="">
	<img style="vertical-align:middle;" src="public/images/icons/ajax-loader.gif" alt="">
</div>
<?php 

	$filterLibrary = 
		is_numeric($this->libraryId) && 0 != $this->libraryId
		? new library($this->libraryId)
		: NULL;
	$filterLibraryLabel = (
		$filterLibrary
		? $filterLibrary->getLibraryName()
		: 'All Libraries'
	);
	$currentStatus = 
		is_numeric($this->statusId) && 0 != $this->statusId
		? new Rd_Request_Status($this->statusId)
		: NULL;
	$filterStatusLabel = (
		$currentStatus
		? $currentStatus->getLabel()
		: 'All Statuses'
	);

?>
<div class="grid_11 bordered appOptions shadowed_near bottomMargin">
	<h3>Filter Requests</h3>
	<form action="index.php?cmd=displayRequest" method="POST">
		<div class="grid_6">
		<label class="blockLabel"><span>Status:</span>
<?php 
		$this->getDisplayer()->renderReserveStatusSelect(array(
			'defaultStatus' => $this->statusId,
			'includeAllOption' => TRUE,
			'excludeActive' => TRUE,
			'excludeInactive' => TRUE,
			'excludeDenied' => TRUE,
			'fieldName' => 'statusId'
		));
?>
		</label>
		</div>
		<div class="grid_4">
		<label class="blockLabel"><span>Library:</span>
			<?php 
			$currentLibrary = array_key_exists('libraryId', $this->request) ? $this->request['libraryId']  : $this->user->getStaffLibrary();
			$this->getDisplayer()->renderLibrarySelect(array(
				'defaultLibrary' => $currentLibrary,
				'includeAllOption' => TRUE,
				'fieldName' => 'libraryId',
				'shortNames' => TRUE
			));?>
		</label>
		</div>
		<input type="submit" value="Go">
	</form>
</div>
<form action="index.php?sort=<? print(array_key_exists('sort', $this->request) ? $this->request['sort'] : ''); ?>&onePerPage=yes" method="POST">
<div class="prefix_1 grid_2">
		<input type="hidden" name="cmd" value="printRequest">
        <!-- <input type="hidden" name="sort" value="<?php print(array_key_exists('sort', $this->request) ? $this->request['sort'] : ''); ?>"> -->
        <input type="hidden" name="no_table">
        <input type="hidden" name="request_id">
		<div>
			<input type="button" value="Print Selected Request" onClick="this.form.cmd.value='printRequest'; this.form.target='printPage'; this.form.submit(); checkAll(this.form, false);">
		</div>
</div>
<div class="clear"></div>
<div class="grid_5">
	<span class="ExpandAll"><a href="#">Expand All</a></span> | <span class="CollapseAll"><a href="#">Collapse All</a></span>
</div>	
<div class="prefix_7 grid_3">
	<?php print(count($this->requestList)); ?>  requests matched
</div>
<div class="clear"></div>
<?php 		
		if (count($this->requestList) > 0)
		{
			$this->getDisplayer()->displayRequestList($this->requestList, $this->request, $this->user, $currentLibrary);
		} else {
			echo "<div>No {$filterStatusLabel} requests to process for this Library.</div>";
		}